/***************************************************************************
 *   Copyright (C) 2007 by Marcin Swiechowicz   *
 *   marcin.swiechowicz@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef KDCABSTRACTKPROCESSJOB_H
#define KDCABSTRACTKPROCESSJOB_H

#include "kdcjob.h"

#include <QStringList>
#include <QPointer>

#include <KProcess>

// base class for all jobs based on kprocess

class KDCAbstractKProcessJob: public KDCJob
{
Q_OBJECT
public:
	KDCAbstractKProcessJob( QObject *parent = 0 );
	virtual ~KDCAbstractKProcessJob();
	void addArgument( const QString& arg, const QString& value = QString(), bool replace = FALSE );
	void clearArguments();
	void setProgram( const QString& program );
	void setWorkingDirectory( const QString& dir );
	void setStandardInputFile( const QString& file );
	void setStandardOutputFile( const QString& file );
	void setNiceLevel( int level );

	QString program() const;
	QStringList arguments() const;
	KProcess* process() const;
	int niceLevel() const;

	static QByteArray extract( QByteArray& data, int start, char end = '\n' );
protected slots:
	virtual void processFinished( int , QProcess::ExitStatus ) = 0;
	virtual void readyReadProcessOutput() = 0;
	virtual void readyReadProcessError();
private:
	QPointer<KProcess> p_process;
	QStringList p_arguments;
	QString p_program;
	int p_niceLevel;
};
#endif
